import { Type, applyDecorators } from '@nestjs/common';
import { ApiOkResponse, ApiProperty, getSchemaPath } from '@nestjs/swagger';
export class ResponseDto<TData> {
  @ApiProperty({
    description: '状态码',
  })
  status: number;

  @ApiProperty({
    description: '成功',
  })
  success: boolean;

  @ApiProperty({
    description: '提示信息',
  })
  message: string;

  result: TData;
}

export const ApiPaginatedResponse = <TModel extends Type<any>>(
  model: TModel,
) => {
  return applyDecorators(
    ApiOkResponse({
      schema: {
        allOf: [
          { $ref: getSchemaPath(ResponseDto) },
          {
            properties: {
              result: {
                allOf: [{ $ref: getSchemaPath(model) }],
              },
            },
          },
        ],
      },
    }),
  );
};
